<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item :to="{ path: '/' }">后台管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>



    <el-divider></el-divider>

    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column prop="id" label="编号" width="50" align="center"></el-table-column>
      <el-table-column prop="phone" label="电话" width="150" align="center"></el-table-column>

      <el-table-column prop="headUrl" label="头像" width="150" align="center">
        <template slot-scope="scope">
          <img style="width: 100px;height: 100px" :src="scope.row.headUrl">
        </template>
      </el-table-column>
      <el-table-column prop="nickname" label="昵称" width="50" align="center"></el-table-column>
      <el-table-column prop="email" label="邮箱" width="150" align="center"></el-table-column>
      <el-table-column prop="gender" label="性别" width="50" align="center"></el-table-column>
      <el-table-column prop="status" label="身份" width="50" align="center"></el-table-column>
      <el-table-column prop="birthady" label="生日" width="150" align="center"></el-table-column>
      <el-table-column prop="blogs" label="博客地" width="150" align="center"></el-table-column>
      <el-table-column prop="dwellingState" label="居住状态" width="50" align="center"></el-table-column>
      <el-table-column prop="hobbies" label="兴趣爱好" width="150" align="center"></el-table-column>
      <el-table-column prop="selfIntroduction" label="自我介绍" width="150" align="center"></el-table-column>
<!--      <el-table-column prop="vip" label="会员" width="30" align="center"></el-table-column>-->


      <el-table-column label="操作" width="50" align="center">
        <template slot-scope="scope">
          <el-button type="danger" icon="el-icon-delete" circle size="mini" @click="openDelectConfirm(scope.row)"></el-button>
        </template>
      </el-table-column>

    </el-table>


  </div>
</template>
<script>
import axios from "axios";

export default {
  data() {
    return {
      tableData: [],
      ruleForm: {

      },
    }
  },
  methods:{
    handleDelect(comment){
      console.log("准备删除"+comment.id)
      let url='http://localhost:8080/adminuser/delete/'+comment.id;
      this.axios.post(url).then((response)=>{
        let responseBody=response.data;
        if(responseBody.state==20000){
          this.loadCommentsList();
          this.$message({
            type: 'success',
            message: '删除成功'
          });
          this.loadCommentsList();
        }else {
          this.$message({
            type: 'info',
            message: responseBody.message
          });
          this.loadCommentsList();
        }
      })
    },
    openDelectConfirm(comment){
      let message='此操作将永久删除该用户《'+comment.phone+'》, 是否继续???';
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelect(comment);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    loadCommentsList(){
      console.log('commentlist')
      let url='http://localhost:8080/adminuser/list';
      console.log('url='+url);
      this.axios.get(url).then((response)=>{
        let responseBody=response.data;
        this.tableData=responseBody.data;
      })
    }
  },
  mounted() {//挂载
    console.log('mounted')
    this.loadCommentsList();
  }

}
</script>